cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/TableA15.log", replace

clear all
set more off

matrix Results = J(33, 8, -9)

use "RawData/GallupDataBJPS.dta", clear

// Drops Unrepresentative Series
drop if drops == "All" | regexm(drops, "Party")
// Drops Obs. w/o Gender
drop if female < 0
// Drops Obs. w/o Weights
drop if final_weight < 0
// Drops Obs. w/o Dem., Ind., or Rep.
keep if party == -1 | party == 0 | party == 1
// Keeps In-Person Surveys
keep if survey == 1

// Sets the Survey Date as the Mid-Point in Field
gen middle_date = .
replace middle_date = floor((start_date + end_date) / 2)
sort middle_date
format middle_date %td
gen year = year(middle_date)  

// Codes Dem. as 0, Ind. as 1/2, and Rep. as 1
// Partisan 1 = Leaners Ind, Partisan 2 = Leaners as Partisans
gen partisan = 0 if party == -1
replace partisan = 1 if party == 1
replace partisan = .5 if party == 0

save "ProcessedData/temp.dta", replace

// Religion
use "ProcessedData/temp.dta", clear
drop if religion < 0
gen prst = (religion == 1)
gen cath = (religion == 2)
gen jwsh = (religion == 3)
gen othr = (religion == 4)
foreach var of varlist prst-othr {
gen femaleX`var' = female * `var'
}
forvalues i = 1953(4)1993 {
local j = 1 + 3*(`i' - 1953)/4
cap areg partisan cath-femaleXothr [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
local temp = _rc
if `temp' == 0 {
mat Results[`j', 1] = _b[femaleXprst]
mat Results[`j' + 1, 1] = -_se[femaleXprst]
cap count if prst == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 1] = r(N)
mat Results[`j', 2] = _b[femaleXcath]
mat Results[`j' + 1, 2] = -_se[femaleXcath]
cap count if cath == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 2] = r(N)
mat Results[`j', 3] = _b[femaleXjwsh]
mat Results[`j' + 1, 3] = -_se[femaleXjwsh]
cap count if jwsh == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 3] = r(N)
mat Results[`j', 4] = _b[femaleXothr]
mat Results[`j' + 1, 4] = -_se[femaleXothr]
cap count if othr == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 4] = r(N)
}
}

// Married
use "ProcessedData/temp.dta", clear
drop if married < 0
gen femaleXyes = female * (married == 1)
gen femaleXno = female * (married == 0)
forvalues i = 1953(4)1993 {
local j = 1 + 3*(`i' - 1953)/4
cap areg partisan married femaleXyes femaleXno [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
local temp = _rc
if `temp' == 0 {
mat Results[`j', 5] = _b[femaleXyes]
mat Results[`j' + 1, 5] = -_se[femaleXyes]
cap count if married == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 5] = r(N)
mat Results[`j', 6] = _b[femaleXno]
mat Results[`j' + 1, 6] = -_se[femaleXno]
cap count if married == 0 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 6] = r(N)
}
}

// Union HH
use "ProcessedData/temp.dta", clear
drop if unionHH < 0
gen femaleXyes = female * (unionHH == 1)
gen femaleXno = female * (unionHH == 0)
forvalues i = 1953(4)1993 {
local j = 1 + 3*(`i' - 1953)/4
cap areg partisan unionHH femaleXyes femaleXno [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
local temp = _rc
if `temp' == 0 {
mat Results[`j', 7] = _b[femaleXyes]
mat Results[`j' + 1, 7] = -_se[femaleXyes]
cap count if unionHH == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 7] = r(N)
mat Results[`j', 8] = _b[femaleXno]
mat Results[`j' + 1, 8] = -_se[femaleXno]
cap count if unionHH == 0 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 8] = r(N)
}
}

matlist Results

log close
